package study.map;

import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Map<String, Person> map = buildMap();
		doIteratorMap1(map);
		System.out.println("=====================");
		doIteratorMap2(map);
		System.out.println("=====================");
		doIteratorMap3(map);
	}

	private static void doIteratorMap1(Map<String, Person> map) {

		Collection<Person> c = map.values();
		for (Iterator<Person> it = c.iterator(); it.hasNext();) {
			Person p = it.next();
			System.out.println(p.toString());
		}
	}

	private static void doIteratorMap2(Map<String, Person> map) {

		Set<String> c = map.keySet();
		for (Iterator<String> it = c.iterator(); it.hasNext();) {
			String key = it.next();
			Person p = map.get(key);
			System.out.println(p.toString());
		}
	}

	private static void doIteratorMap3(Map<String, Person> map) {

		Set<Map.Entry<String, Person>> set = map.entrySet();
		for (Iterator<Map.Entry<String, Person>> it = set.iterator(); it
				.hasNext();) {
			Map.Entry<String, Person> entry = it.next();
			Person p = entry.getValue();
			System.out.println(p.toString());
		}
	}

	private static Map<String, Person> buildMap() {

		Person p = null;
		Map<String, Person> map = new HashMap<String, Person>();
		for (int i = 0; i < 10; i++) {
			p = new Person();
			p.setName("name" + i);
			p.setSex("sex" + i);
			p.setAge(50 + i);
			p.setAddress("address" + i);
			p.setWork("work" + i);
			map.put(String.valueOf(i), p);
		}

		return map;
	}
}
